
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.miage.shopping.presentation;

import fr.miage.shopping.presentation.panel.*;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import fr.miage.shopping.metier.entite.*;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * Ecran d'accueil
 * @author romain
 */
public class MonAccueil extends JFrame {

    private Menu2 menu;
    private Panier panier;
    private Gestionnaire gest;
    private ListProduit listP; 
    private Admin admin;
    private Client client;
    private JButton ajouterPanier;

    public MonAccueil(Admin admin, Client client){
        this.admin = admin;
        this.client = client;
        init();
    }

    private void init() {
        Toolkit outil = getToolkit();
        this.setSize(outil.getScreenSize()); //this étant L'instance de la JFrame
        Container pane = this.getContentPane();
        if(admin!=null){
            if(admin.getRole().getRole().equalsIgnoreCase("SUPERVISEUR")){
                gest = new Gestionnaire(true);
            }
            else {
                gest = new Gestionnaire(false);
            }


            pane.add(gest,BorderLayout.EAST);
        }
        else if (client!=null){
            panier = new Panier(client);
            pane.add(panier,BorderLayout.EAST);
                    ajouterPanier = new JButton("Ajouter le produit au panier");

        ajouterPanier.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                Vector v = listP.getSelectedRow();
                if (v.size() >0) {
                    panier.ajouterElement(v);
                }
            }
        });

        JPanel panelJ=new JPanel();
        panelJ.add(ajouterPanier,BorderLayout.SOUTH);
        pane.add(panelJ,BorderLayout.SOUTH);
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        }
        menu = new Menu2();
        listP = new ListProduit();
        menu.setListeProduit(listP);
        pane.add(listP,BorderLayout.CENTER);
        pane.add(menu,BorderLayout.WEST);
    }


    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }
}